new at_tab("tabdom");
/* 重磅推荐左右滚动 */
var saidyhuio233 = window.setTimeout(function(){
    var let=$("#gunlr li.let"),
        rit=$("#gunlr li.rit"),
        p=$("#gunlr li.con"),
        size=$("#gunlr li.con td").size()/2,
        n=1,
        width=p.find("td").eq(0).outerWidth(true)*2;
    let.click(function(){
        if(n==1 || p.is(":animated")) return false;
        p.animate({scrollLeft:p.scrollLeft()-width},"normal",function(){
            n--;
        });
    }).hover(
        function(){
            $(this).fadeTo("fast",0.5);
        },function(){
            $(this).fadeTo("fast",1);
        }
    );
    rit.click(function(){
        if( n==size || p.is(":animated")){return false;}
        p.animate({scrollLeft:p.scrollLeft()+width},"normal",function(){
            n++;
        });
    }).hover(
        function(){
            $(this).fadeTo("fast",0.5);
        },function(){
            $(this).fadeTo("fast",1);
        }
    );
},500);

function contentSwap(){
	var co_a=$("#at-colist li.co_a");
    var co_c=$("#at-colist li.co_c");
    var co_b=$("#at-colist li.co_b");
    if($.browser.mozilla || $.browser.opera  || $.browser.safari || $.browser.chrome)
    {
        co_b.find("p").css("position","relative");
    }
    var a=co_b.find("a");
    var width=50;
    var timer=null;
    var timer2=null;
    var timer3=null;
    var timer4=null;
    var isWaiting=false;//是否处于读取数据的状态中
    //获取数据
    function getData(ptype,cl,fn)
    {
        isWaiting=true;
        $.getJSON("http://u.zhubajie.com/follow/taskcontent?cid="+cl+"&jsoncallback=?",function(json){
            isWaiting=false;
            if(json.state==1)
            {
                fn(json.msg);
            }else{
                fn(false);
            }
        });
    }
    //显示隐藏dl
    function showDL($this,as,dls,cl,colist_c)
    {
        //调整分类名称的位置
        var oleft=$this.get(0).offsetLeft;
        var li=$this.parents("li");
        var sleft=li.scrollLeft();
        var o_w=$this.outerWidth();
        
        if(sleft>oleft)
        {
            li.animate({scrollLeft:oleft-o_w},"fast");
        }else if((oleft+o_w-li.width())>sleft){
            li.animate({scrollLeft:oleft-li.width()+o_w*2},"fast");
        }
        
        hideWaiting(colist_c,true);
        as.removeClass("cousel");
        $this.addClass("cousel");
        dls.removeClass("cousel");
        var cur_dl=dls.filter("[name='"+cl+"']");
        var ptype=$this.parents(".colist_t").find("a.ptype").attr("value");
        if(cur_dl.size()>0){
            cur_dl.addClass("cousel");
        }else{
            //显示等待图标
            showWaiting(colist_c);
            getData(ptype,cl,function(html){
                if(html)
                {
                    hideWaiting(colist_c,true);
                    colist_c.append(html);
                }else{
                    hideWaiting(colist_c,false);
                }
                //当不处于读取状态时，才显示需要显示的dl
                if(!isWaiting){
                    colist_c.find("dl").removeClass("cousel").filter("[name='"+ as.filter(".cousel").attr("cl")+"']").addClass("cousel");
                }
            });
        }
    }
    //显示等待图标
    function showWaiting(colist_c)
    {
        //隐藏可能的错误提示
        colist_c.find("span.at_text").hide();
        var wait=colist_c.find("img.waiting");
        if(wait.size()==0)
        {
            colist_c.append("<img style=\"display: block; position: relative; left: 374px; top: 100px;\" class=\"waiting\" src=\"http://s.zbjimg.com/img/write_max.gif\">");
        }else{
            wait.show();
        }
    }
    //隐藏等待图标
    function hideWaiting(colist_c,nomsg)
    {
        colist_c.find("img.waiting").hide();
        var error=colist_c.find("span.at_text");
        if(!nomsg)
        {
            if(error.size()>0)
            {
                error.show();
            }else{
                colist_c.append("<span class=\"at_text\" style=\"position: relative; left: 315px; top: 100px;\"><em><u class=\"at_msg m_3_e\"></u>对不起，读取不到数据</em></span>");
            }
        }else{
            error.hide();
        }
    }
	function bindA(a,fn)
    {
		a.unbind("mouseover");
        a.mouseover(function(){
            var $this=$(this);
            var cl=$this.attr("cl");
            if(!cl){return false;}
            timer4=window.setTimeout(function(){
                var colist=$this.parents(".colist");
                var colist_c=colist.find("div.colist_c");
                var dls=colist.find("dl");
                var as=$this.parent().find("a");
                showDL($this,as,dls,cl,colist_c);
            },200);
        }).mouseout(function(){
            clearTimeout(timer4);
        });
        if(fn){fn();}
    }
    bindA(a);
    window["bindA"]=bindA;
    
    function co_c_click(obj)
    {
        clearTimeout(timer2);
        var co_b=obj.parent().find("li.co_b");
        if(co_b.is(":animated")){return false;}
        co_b.animate({scrollLeft:co_b.scrollLeft()+width},"fast",function(){
            var colist=co_b.parents(".colist");
            var colist_c=colist.find("div.colist_c");
            var dls=colist_c.find("dl");
            var as=co_b.find("a");
            var as_size=as.size();
            var curi=0;
            as.each(function(index){
                if($(this).hasClass("cousel")){
                    curi=index;
                }
            });
            if(curi==as_size-1){
                return false;
            }else{
                curi++;
            }
            var cl=as.eq(curi).attr("cl");
            if(!cl){return false;}
            showDL(as.eq(curi),as,dls,cl,colist_c);
        });        
    }
    
    co_c.click(function(){
        co_c_click($(this));
    }).mousedown(function(){
        var co_b=$(this).parent().find("li.co_b");
        timer3=setTimeout(function(){
            timer=setInterval(function(){
                co_b.scrollLeft(co_b.scrollLeft()+3);
            },1);
        },50);
        timer2=setTimeout(function(){
            co_c.unbind("click");
        },200);
    }).mouseup(function(){
        var co_b=$(this).parent().find("li.co_b");
        clearTimeout(timer3);
        clearInterval(timer);
        clearTimeout(timer2);
        timer2=setTimeout(function(){
            co_c.click(function(){
                co_c_click($(this));
            });
        },200);
    }).each(function(){$(this).attr("title","试试看按住鼠标左键不放")});
    
    function co_a_click(obj)
    {
        clearTimeout(timer2);
        var co_b=obj.parent().find("li.co_b");
        if(co_b.is(":animated")){return false;}
        co_b.animate({scrollLeft:co_b.scrollLeft()-width},"fast",function(){
            var colist=co_b.parents(".colist");
            var colist_c=colist.find("div.colist_c");
            var dls=colist_c.find("dl");
            var as=co_b.find("a");
            var as_size=as.size();
            var curi=0;
            as.each(function(index){
                if($(this).hasClass("cousel")){
                    curi=index;
                }
            });
            if(curi==0){
                return false;
            }else{
                curi--;
            }
            var cl=as.eq(curi).attr("cl");
            showDL(as.eq(curi),as,dls,cl,colist_c);
        });        
    }
    co_a.click(function(){
        co_a_click($(this));
    }).mousedown(function(){
        var co_b=$(this).parent().find("li.co_b");
        timer3=setTimeout(function(){
            timer=setInterval(function(){
                co_b.scrollLeft(co_b.scrollLeft()-3);
            },1);
        },50);
        timer2=setTimeout(function(){
            co_a.unbind("click");
        },200);
    }).mouseup(function(){
        var co_b=$(this).parent().find("li.co_b");
        clearInterval(timer);
        clearTimeout(timer2);
        clearTimeout(timer3);
        timer2=setTimeout(function(){
            co_a.click(function(){
                co_a_click($(this));
            });
        },200);
    }).each(function(){$(this).attr("title","试试看按住鼠标左键不放")});
    
    var colist_c=$("#at-colist div.colist_c");
    colist_c.css("height","255px");
    /*fix_ff*/
    if($.browser.mozilla)
    {
        colist_c.css("margin-top","1px");
    }
}


/*新发布和中标信息滚动*/
function marqueeNews(){
	var len = arguments.length;
	if(len <= 0)
		return ;
    var scroll=function(uls){
        //复制一次内部的li
        var li_h=uls.eq(0).find("li").outerHeight();
        this.copy=function(){
            uls.each(function(){
                var lis=$(this).find("li");
                $(this).append(lis.clone());
                $(this).attr("li_s",lis.size()*2);
                $(this).attr("cur_li",lis.size()*2-1);
            });
        }
        this.copy();
        //移动到最下边的li
        this.toLast=function(){
            uls.each(function(){
                $(this).scrollTop(10000);
            });
        }
        this.toLast();

        var timer=null;//滚动的超时时间
        var i=0;
        //开始滚动ul数组
        function start(i)
        {
            var cur_ul=uls.eq(i);
            if(cur_ul){
                cur_ul.animate({scrollTop:cur_ul.scrollTop()-li_h},function(){
                    var cur_li=parseInt(cur_ul.attr("cur_li"));
                    var li_s=parseInt(cur_ul.attr("li_s"));
                    cur_li--;
                    if((li_s/2-1)==cur_li)
                    {
                        cur_ul.attr("cur_li",li_s-1);
                        $(this).scrollTop(10000);
                    }else{
                        cur_ul.attr("cur_li",cur_li);
                    }
                    start(++i);
                });
            };
        }
        timer=setInterval(function(){ start(i);},7000);
    }
    for(var j = 0; j < len; j++) {
    	scroll($('#'+ arguments[j]).find('ul'));
	}
}

//倒计时
function reverseTimer(cid, cls) {
	//传入时分秒容器
	var secondsShow = function(h, m, s) {
		this.h_n = null; 
		this.m_n = null;
		this.s_n = null;
		this.irv = null;
		var _this = this;
		//init
		this.init = function() {
			this.h_n = parseInt(h.text()); 
			this.m_n = parseInt(m.text());
			this.s_n = parseInt(s.text());
		}
		this.init();
		//interval
		this.irv = window.setInterval(function() {
			if(_this.s_n-1 >= 0) {
				s.text(_this.s_n-1);
			} else {
				s.text(59);
				if(_this.m_n-1 >= 0) {
					m.text(_this.m_n-1);
				} else {
					m.text(59);
					if(_this.h_n-1 >= 0) {
						h.text(_this.h_n-1);
					} else {
						window.clearInterval(_this.irv);
						h.parent().html("已结束");
					}
				}
			}
			_this.init();
		},1000);
	}
	//init
	var con = $("#" + cid),
	time = con.find(cls),
	item = null;
	for(var i=0; i<time.length; i++) {
		item = time.eq(i).children("u");
		new secondsShow(item.eq(0), item.eq(1), item.eq(2));
	}
}
$(document).ready(function(){
	new at_imgSwitch("at_imgSwitch",true);
	new at_imgSwitch("at_imgSwitch2",true,6000);
	contentSwap();
	marqueeNews('dota1', 'dota2');
	reverseTimer('at-colist', 'i.d_time');
});